package com.edu.hit.showdemo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.*;

@RestController
public class StartController {
    @Autowired
    HttpServletRequest request;

    @CrossOrigin
    @RequestMapping(method = RequestMethod.POST, value = "start", produces = "application/json;charset=UTF-8", consumes = "application/json")
    public String savetofile() throws IOException {

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF-8"));
        String path = "./data.json";
        File file = new File(path);
        FileOutputStream fileOutputStream = new FileOutputStream(file);
        String line = null;
        while ((line = bufferedReader.readLine()) != null) {
            fileOutputStream.write(line.getBytes());
        }
        fileOutputStream.close();

        App.main(null);

        return "推理完成";
    }




}
